<template>
  <div class="app-container">
    <div class="zd3">
      <div class="zd3-title">
        <p>
          <span>部门</span>
          <input v-model="content" type="text" placeholder="请输入部门" />
        </p>
        <h3 @click="seachList">查询</h3>
        <h4 @click="resetList">重置</h4>
				<h3 @click="addPermission" style="background: #0093FF">新增</h3>
      </div>
      <div class="zd3-btm">
        <el-table
          :data="tableData"
          style="width: 100%;border-radius: 8px;"
          :show-header="showHeader"
          v-loading="loading"
        >
          <el-table-column type="index" align="center" label="序号" width="80" />
          <el-table-column align="center" prop="jiaoshi" label="教室" />
					<el-table-column align="center" prop="bumen" label="部门" />
					<!-- <el-table-column align="center" prop="uptime" label="开始" />
					<el-table-column align="center" prop="downtime" label="结束" /> -->
					<el-table-column align="center" prop="person" label="培训人" />
					<el-table-column align="center" prop="number" label="电话" />
					<!-- <el-table-column align="center" prop="contents" label="培训内容" /> -->
          <el-table-column align="center" width="200" label="培训内容" >
						<template slot-scope="scope">
							<div class="ellisp">{{scope.row.contents}}</div>
						</template>
					</el-table-column>
					<el-table-column align="center" prop="starttime" label="开始时间" />
					<el-table-column align="center" prop="endtime" label="结束时间" />
          <el-table-column align="center" width="200" label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="write(scope.row,scope.$index)">编辑</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
					align="right"
					:page-size="50"
          layout="prev, pager, next"
          :total="total"
					@current-change='goPage'
          @prev-click="goPrev"
          @next-click="goNext"
        />
      </div>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      :modal-append-to-body="false"
      :modal="true"
      :close-on-click-modal="false"
      width="70%"
    >
      <div class="change">
        <p>
          <span>教室</span>
          <el-select v-model="tempData.jiaoshi" placeholder="请选择职教室" class="userselect">
            <el-option
              v-for="item in classroom"
              :key="item.value"
              :label="item.name"
              :value="item.name"
            ></el-option>
          </el-select>
        </p>
				<p>
				  <span>部门</span>
				  <el-select v-model="tempData.bumen" placeholder="请选择部门" class="userselect">
				    <el-option
				      v-for="item in ifydata"
				      :key="item.id"
				      :label="item.departments"
				      :value="item.departments"
				    ></el-option>
				  </el-select>
				</p>
				<!-- <p>
				  <span>开始</span>
				  <input v-model="tempData.uptime" type="text" placeholder="上午" />
				</p>
				<p>
				  <span>结束</span>
				  <input v-model="tempData.downtime" type="text" placeholder="下午" />
				</p> -->
				<p>
				  <span>培训人</span>
				  <input v-model="tempData.person" type="text" placeholder="请输入培训人" />
				</p>
				<p>
				  <span>培训内容</span>
				  <input v-model="tempData.contents" type="text" placeholder="请输入培训内容" />
				</p>
				<p>
				  <span>电话</span>
				  <input v-model="tempData.number" type="number" maxlength="11" placeholder="请输入电话" />
				</p>
				<p>
				  <span>开始时间</span>
					<el-date-picker
						v-model="tempData.starttime"
						type="datetime"
						class="userselect"
						value-format="yyyy-MM-dd HH"
						placeholder="选择开始时间">
					</el-date-picker>
				</p>
				<p>
				  <span>结束时间</span>
					<el-date-picker
						v-model="tempData.endtime"
						type="datetime"
						class="userselect"
						value-format="yyyy-MM-dd HH"
						placeholder="选择结束时间">
					</el-date-picker>
				</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="save">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getClassroom,addClassroom,updateClassroom,deleteClassroom} from "@/api/oneclassify"
import { getUser,getBumen } from '@/api/people'
export default {
  data() {
    return {
      content: "",
      total: 1,
			page: 1,
      showHeader: true,
      loading: true,
      tableData: [],
      dialogVisible: false,
      tempData: "",
      tempIndex: -1,
			ifydata: [],   //部门列表
			classroom: [
				{
					name: '职教室一',
					value: 1
				},
				{
					name: '职教室二',
					value: 2
				},
				{
					name: '职教室三',
					value: 3
				}
			]  //职教室列表
    };
  },
  mounted() {
    this.seachList()
		this.bumen()
  },
  methods: {
		seachList(){
			this.page = 1
			let mydata = new Date()
			// console.log(mydata.toLocaleDateString().replace(/\//g,'-'))
			const kaishi = mydata.toLocaleDateString().replace(/\//g,'-')
			const param = {
			  bumen: this.content ? this.content : null,
				starttime: kaishi,
				currentPage: this.page
			}
			this.getList(param)
		},
    getList(param) {
			let value = param || {}
      getClassroom(value).then(res => {
        console.log(res);
        this.tableData = res.data.records;
        this.loading = false;
				this.total = res.data.total
      });
    },
		bumen(){
			getBumen({}).then(res => {
				console.log(res)
				this.ifydata = res.data
			})
		},
    write(item, index) {
      console.log(item);
      this.tempIndex = index;
      this.tempData = { ...item };
      this.dialogVisible = true;
    },
    save() {
      if (this.tempIndex == -1) {
        addClassroom(this.tempData).then(res => {
          console.log(res);
          this.$message({
            showClose: true,
            message: res.message,
            type: "success"
          });
          this.seachList();
          this.dialogVisible = false;
        });
      } else {
				delete this.tempData.insertTime
				delete this.tempData.updateTime
        updateClassroom(this.tempData).then(res => {
          console.log(res);
          this.$message({
            showClose: true,
            message: res.message,
            type: "success"
          });
          this.seachList();
          this.dialogVisible = false;
        });
      }
    },
    deleteRow(item) {
      console.log("删除");
      deleteClassroom(item.id).then(res => {
        console.log(res);
        this.$message({
          showClose: true,
          message: res.message,
          type: "success"
        });
        this.getList();
      });
    },
    goPrev(page) {
      console.log(page);
			this.page--
			this.getList()
			this.backtop()
    },
    goNext(page) {
      console.log(page);
			this.page++
			this.getList()
			this.backtop()
    },
		goPage(page){
			console.log(page)
			this.page = page
			this.getList()
			this.backtop()
		},
		// 回到顶部
		backtop(){
			document.documentElement.scrollTop = document.body.scrollTop = 0;
			// var timer = setInterval(function(){
			// 	let osTop = document.documentElement.scrollTop || document.body.scrollTop;
			// 	let ispeed = Math.floor(-osTop / 5); 
			// 	document.documentElement.scrollTop = document.body.scrollTop = osTop + ispeed;
			// 	this.isTop = true;
			// 	if(osTop === 0){
			// 		clearInterval(timer);
			// 	}
			// },30)
		},
    resetList() {
      this.content = "";
    },
    addPermission(item) {
      this.dialogVisible = true
      this.tempIndex = -1
      this.tempData = {
        bumen: "",
				downtime: "",
				endtime: "",
				jiaoshi: "",
				number: "",
				person: "",
				starttime: "",
				uptime: ""
      }
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e !important;
  border-color: #18a05e !important;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
  background: #18a05e !important;
  border-color: #18a05e !important;
  color: #fff !important;
}
/deep/.el-button:hover,
.el-button:focus {
  color: #18a05e;
  background-color: transparent;
}
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e;
  border-color: #18a05e;
}
/deep/.el-button--text {
  color: #00c666 !important;
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #18a05e;
  color: #fff;
}
.zd3-btm /deep/.btn-prev:after {
  content: "上一页";
}
.zd3-btm /deep/.btn-next:before {
  content: "下一页";
}
.zd3-btm /deep/.btn-prev,
.zd3-btm /deep/.btn-next {
  width: 65px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.app-container {
  padding: 10px;
}
.ellisp{
	width: 100%;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	overflow: hidden;
	text-align: left;
}
.rolestip {
  width: 100%;
  display: flex;
  justify-content: center;
}
.inps {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: #333;
}
.inps-active {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  // background:#ccc;
  border: none;
  color: #333;
}
.s-img{
  width: 80px;
  height: 80px;
}
.zd3-title {
	height: 80px;
	display: flex;
	align-items: center;
	padding: 0 20px;
	position: relative;
	background: #ffffff;
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.1);

	> p {
		font-size: 14px;
		color: #333;
		margin-right: 30px;

		> span {
			padding-right: 20px;
		}

		> input {
			width: 200px;
			height: 32px;
			// background: #ccc;
			border-radius: 3px;
			border: 1px solid #ccc;
			padding-left: 10px;
			color: #333;
		}
	}

	> h3 {
		width: 64px;
		height: 32px;
		background: #18a05e;
		border-radius: 3px;
		margin: 0 30px 0 0;
		color: #fff;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
	}

	> h4 {
		width: 64px;
		height: 32px;
		border-radius: 3px;
		border: 1px solid rgba(0, 0, 0, 0.1);
		color: #333;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
		margin-right: 30px;
	}
}

.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
	.el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.25);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.change {
  display: flex;
  flex-wrap: wrap;
  > p {
    width: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      // max-width: 250px;
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
  }
}
</style>
